<?php

/*
	This file is part of Mandragon.

    Mandragon is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Mandragon is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Mandragon.  If not, see <http://www.gnu.org/licenses/>.
*/

class WebLink extends BaseTopic implements iEditBody {

	public function prepare($new, $item, $inputs) {
		$inputs[] = $this->creator->input_field("Link", 
				"link", 
				$new ? "http://" : $this->db_access->db_desqlize($item['link']));
		return $this->create_body("Beschrijving", $item, $inputs);
	}

	public function check_content($values, $new) {
		return $this->checker->checkLink($ok, $values);
	}

	public function get_edit_body() {
		$link = $this->get_item_from_database();
		return $link['body'];
	}

	public function get_edit_link() {
		$link = $this->get_item_from_database();
		return $link['link'];
	}

	protected function derive_info() {
		return substr($_POST['link'], 0, 50) . ((strlen($_POST['link']) > 50) ? "&hellip;" : "");
	}

	protected function get_sql_from_post($item_id) {
		return $this->db_access->db_query_insert(
				array('item_id', 'link', 'body'), 
				array($item_id, 
						$this->db_access->db_sqlize($_POST['link']), 
						$this->db_access->db_sqlize($_POST['body'])), "LINK");
	}

	private function get_item_from_database() {
		$sql = $this->db_access->db_query_select(
				array(array('*')), 
						array("LINK"), 
						"item_id = {$this->id}");
		$sqlresult = $this->db_access->db_do_query($sql);
		return $this->db_access->db_fetch_array($sqlresult);
	}
}

?>
